<template>
  <!-- 头部操作 -->
  <div class="dialog-head">
    <div class="dialog-search-box">
      <input type="text" v-model="keyword" placeholder="搜索" />
    </div>

    <div class="dialog-search-add" @click="addNewDialog"></div>
  </div>
</template>

<script setup lang="ts">
import { useChatStore } from "@/store/useChatStore";
import { ref } from "vue";
import { useRouter } from "vue-router";

const emits = defineEmits(["getDialogs"]);

const router = useRouter();
const chatStore = useChatStore();
// const sessions = ref(chatStore.sessions);
// const currentSessionIndex = chatStore.currentSessionIndex;

const keyword = ref("");
// 添加新对话
const addNewDialog = () => {
  let session = chatStore.openSession();
  // 点击时跳转到对应的界面，并传递必要参数信息
  chatStore.selectSession(0);
  router.push({ path: `/chat/${session.id}` });

  // 重新获取会话列表
  emits("getDialogs");
};
</script>

<style scoped lang="scss">
.dialog-head {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  height: 30px;
  padding: 15px;
  margin-top: 15px;
  margin-bottom: 10px;
  cursor: pointer;

  p {
    margin: 0;
  }

  background-color: #ffffff;
}

.dialog-search-box {
  flex: 1;
  display: flex;
  max-width: calc(100% - var(--dialog-search-add));
  height: 32px;
  background-color: #f2f2f2;
  border-radius: 4px;
  padding: 0 10px;
}

.dialog-search-box input {
  flex: 1;
  height: 100%;
  border: none;
  background-color: transparent;
  outline: none;
  font-size: 12px;
  text-align: left;
}

.dialog-search-add {
  display: flex;
  justify-content: space-between;
  width: 32px;
  height: 32px;
  background-color: #05b977;
  border-radius: 4px;
  margin-left: 10px;
  position: relative;
}

.dialog-search-add::before,
.dialog-search-add::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 15px;
  height: 1px;
  font-size: 12px;
  background-color: #fffefe;
}

.dialog-search-add::before {
  transform: translate(-50%, -50%) rotate(90deg);
}

.dialog-search-add::after {
  transform: translate(-50%, -50%);
}
</style>
